<template>
	<view>
		<view class="search">
			<view class="icon-cl">
				<image class="icon" src="/static/myorder/search.png" />
			</view>
			<input class="text" v-model="query" @input="search" placeholder="输入关键字搜索" />
		</view>

		<view class="results">
			<view v-for="(item, index) in filteredResults" :key="index" class="result-item">{{ item.title }}</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "Search",
		data() {
			return {
				query: "",
				results: []
			};
		},
		methods: {
			async search() {
				// 获取用户输入的查询字符串
				const query = this.query.trim().toLowerCase();

				if (!query) {
					this.results = [];
					return;
				}

				// try {
				// 	const res = await axios.get(`http://172.29.15.165:8081/business/getActivities?name=${query}`, {
				// 		headers: {
				// 			Authorization: this.userdata.token,
				// 			'content-type': 'application/x-www-form-urlencoded',
				// 		}
				// 	});
				// 	this.results = res.data.data; // 将接口返回的数据存储到组件的data中
				// } catch (error) {
				// 	console.log(error);
				// }
			},
		},
		computed: {
			filteredResults() {
				return this.results.filter(result => result.title.includes(this.query));
			}
		}
	};
</script>


<style>
	/* 搜索框样式 */

	.search {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		margin-left: 3%;
		width: 94%;
		height: 60rpx;
		background-color: whitesmoke;
		margin-top: 5%;
		border: 1rpx solid whitesmoke;
		border-radius: 20rpx;
	}

	/* 搜索框提示文字样式 */
	.search input {
		font-size: 27rpx;
		font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
		padding-left: 30rpx;
	}

	/* 搜索框小图标 */
	.search image {
		width: 40rpx;
		height: 40rpx;
		padding-right: 20rpx;
	}
</style>